// created by noellynch
// May 6, 2009

package com.sceneworker.app.globals;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.BoxLayout;
import javax.swing.JCheckBox;
import javax.swing.JPanel;

import com.myjavautils.swing.MigLayoutUtils;
import com.myjavautils.swing.SwingComponentFactory;
import com.sceneworker.app.globals.SceneWorkerPreferencesPanel.IPrefsPanel;

public class SpatialPrefsPanel extends JPanel implements IPrefsPanel{

	private		boolean			mb_integerSnapOn;
	private		boolean			mb_zoomOnSelectedObjects;
	private		boolean			mb_dropObjectsAtCamera;
	
	public	SpatialPrefsPanel() {
		MigLayoutUtils.asMigLayout(this);
		
		JCheckBox		lcl_integerSnapOn = SwingComponentFactory.makeACheckBox("Integer Snap On", SceneWorkerGlobals.inst().getIntegerSnapOn());
		mb_integerSnapOn = SceneWorkerGlobals.inst().getIntegerSnapOn();
		lcl_integerSnapOn.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent e) {
				mb_integerSnapOn = !mb_integerSnapOn;
			}
		});
		add(lcl_integerSnapOn, "wrap");
		
		JCheckBox		lcl_zoomOnSelectedObjects = SwingComponentFactory.makeACheckBox("Zoom On Objects Selected From Scene Tree", SceneWorkerGlobals.inst().getZoomOnSelectedObjects());
		mb_zoomOnSelectedObjects = SceneWorkerGlobals.inst().getZoomOnSelectedObjects();
		lcl_zoomOnSelectedObjects.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent e) {
				mb_zoomOnSelectedObjects = !mb_zoomOnSelectedObjects;
			}
		});
		add(lcl_zoomOnSelectedObjects, "wrap");
		
		JCheckBox		lcl_dropAtCamera = SwingComponentFactory.makeACheckBox("Place created/pasted objects in front of camera", SceneWorkerGlobals.inst().getDropAtCamera());
		mb_dropObjectsAtCamera = SceneWorkerGlobals.inst().getDropAtCamera();
		lcl_dropAtCamera.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				mb_dropObjectsAtCamera = !mb_dropObjectsAtCamera;
			}
		});
		add(lcl_dropAtCamera, "wrap");
	}
	
	public void apply() {
		if(mb_integerSnapOn != SceneWorkerGlobals.inst().getIntegerSnapOn()) {
			SceneWorkerGlobals.inst().setIntegerSnapOn(mb_integerSnapOn);
		}
		
		if(mb_zoomOnSelectedObjects != SceneWorkerGlobals.inst().getZoomOnSelectedObjects()) {
			SceneWorkerGlobals.inst().setZoomOnSelectedObjects(mb_zoomOnSelectedObjects);
		}
		
		if(mb_dropObjectsAtCamera != SceneWorkerGlobals.inst().getDropAtCamera()) {
			SceneWorkerGlobals.inst().setDropAtCamera(mb_dropObjectsAtCamera);
		}
	}
	
	
}
